#include "qbytearrayproperty.h"

#include <QLineEdit>

QByteArrayProperty::QByteArrayProperty(SHAREDLIB::QAbstractProperty *parent):
    SHAREDLIB::QAbstractProperty(parent)
{
    connect(this,SIGNAL(showValueChanged()),this,SLOT(value_changed()));
}

void QByteArrayProperty::valueXML(QXmlStreamWriter *w)
{
    w->writeAttribute("value",getValue().toString());
}

QWidget* QByteArrayProperty::getEditor()
{
    if(attribute("editabled").toBool())
    {
        QLineEdit *e=new QLineEdit;
        connect(e,SIGNAL(textEdited(QString)),this,SLOT(textChanged(QString)));
        m_editor=e;
    }
    return QAbstractProperty::getEditor();
}

void QByteArrayProperty::textChanged(const QString &text)
{
    if(text!=getValue().toString())
    {
        setModified(true);
        setSignalValue(text);
    }
}

void QByteArrayProperty::value_changed()
{
    if(m_editor!=NULL)
    {
        ((QLineEdit*)m_editor)->setText(m_value.toString());
    }
}
